package com.jinzhi.aop;

import com.jinzhi.common.utils.ShiroUtils;
import com.jinzhi.sys.domain.UserDO;
import com.jinzhi.sys.service.UserRoleService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.file.AccessDeniedException;

/**
 * @author mengzhichao
 * @create 2025-05-07-20:32
 */
@Aspect
@Component
public class PermissionAspect {

    @Autowired
    private UserRoleService userRoleService;

    public UserDO getUser() {
        return ShiroUtils.getSysUser();
    }

    public Long getUserId() {
        return getUser().getId();
    }


    @Around("@annotation(permissionRequired)")
    public Object checkPermission(ProceedingJoinPoint joinPoint,
                                  PermissionRequired permissionRequired) throws Throwable {
//        // 获取当前用户角色权限
//        Integer is = userRoleService.userRolenum(this.getUserId());
//        if(is !=4) {
//            throw new AccessDeniedException("无权限访问");
//        }
        return joinPoint.proceed();
    }
}